package com.rc.object;

import android.annotation.SuppressLint;

import com.rc.activity.dao.tbl_Report;
import com.rc.util.Util;

public class ReportObj extends tbl_Report {

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	public static String[] keys = { "ReportID", "Title", "Amount", "Date",
			"IsArchived", "ReportType", "ApproverEmail", "CreatedTime",
			"Approved", "Claimed", "Reference", "IsSubmitted", "IsApproved" };
	public static String REPORT_ID = keys[0];
	public static String TITLE = keys[1];
	public static String AMOUNT = keys[2];
	public static String DATE = keys[3];
	public static String IS_ARCHIVED = keys[4];
	public static String REPORT_TYPE = keys[5];
	public static String APPROVER_EMAIL = keys[6];
	public static String CREATED_TIME = keys[7];
	public static String APPROVED = keys[8];
	public static String CLAIMNED = keys[9];
	public static String REFERENCE = keys[10];
	public static String IS_SUBMITTED = keys[11];
	public static String IS_APPROVED = keys[12];

	@SuppressLint("SimpleDateFormat")
	public static tbl_Report getReportbyBaseObject(BaseObject baseObject) {
		if (baseObject == null) {
			return null;
		}

		float amount = !"null".equals(baseObject.getParam(AMOUNT)) == true ? Float
				.valueOf(baseObject.getParam(AMOUNT)) : 0;
		String mDate = baseObject.getParam(DATE);

		String mCreateTime = baseObject.getParam(CREATED_TIME);
		if (mCreateTime != null) {
			mCreateTime = Util.formateDateFromstring("yyyy-MM-dd'T'HH:mm",
					"dd-MM-yyyy", mCreateTime);
		}
		int mDateInt = 0;
		if (mDate != null) {
			mDate = Util.formateDateFromstring("yyyy-MM-dd'T'HH:mm",
					"dd-MM-yyyy", mDate);
			mDateInt = Util.parseDateForInt(mDate);
		}
		return new tbl_Report(baseObject.getParamLong(REPORT_ID),
				baseObject.getParam(TITLE), amount + "",
				baseObject.getParam(APPROVED), mDate, "1",
				Integer.valueOf(baseObject.getParam(IS_ARCHIVED)),
				baseObject.getParam(REPORT_TYPE),
				baseObject.getParam(APPROVER_EMAIL), mCreateTime,
				baseObject.getParam(CLAIMNED), "", "", "",
				baseObject.getParam(REFERENCE), false, mDateInt,
				baseObject.getParamInt(IS_SUBMITTED), "",
				baseObject.getParamInt(IS_APPROVED));
	}
}
